//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
#include "ExtractComplexSeparated.h"
#include "BoxBindingZone.h"
#include "Strings.h"
#include "ListE.h"

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <dirent.h>

#include <fstream>
#include <iostream>

#include <zlib.h>
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
#define LENGTHLINE 5000
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
using namespace std;
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
ExtractComplexSeparated::ExtractComplexSeparated() {
  this->location                = new String();
  this->listInFilename          = new String();
  this->locationLigandOut       = new String();
  this->locationProteinOut      = new String();
  this->listResiduesBindingSite = new String();
  this->outList                 = new String();
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
ExtractComplexSeparated::ExtractComplexSeparated(const ExtractComplexSeparated& extractComplexSeparated) {
  this->location                = new String(extractComplexSeparated.location);
  this->listInFilename          = new String(extractComplexSeparated.listInFilename);
  this->locationLigandOut       = new String(extractComplexSeparated.locationLigandOut);
  this->locationProteinOut      = new String(extractComplexSeparated.locationProteinOut);
  this->listResiduesBindingSite = new String(extractComplexSeparated.listResiduesBindingSite);
  this->outList                 = new String(extractComplexSeparated.outList);
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
ExtractComplexSeparated::ExtractComplexSeparated(const ExtractComplexSeparated* extractComplexSeparated) {
  this->location                = new String(extractComplexSeparated->location);
  this->listInFilename          = new String(extractComplexSeparated->listInFilename);
  this->locationLigandOut       = new String(extractComplexSeparated->locationLigandOut);
  this->locationProteinOut      = new String(extractComplexSeparated->locationProteinOut);
  this->listResiduesBindingSite = new String(extractComplexSeparated->listResiduesBindingSite);
  this->outList                 = new String(extractComplexSeparated->outList);
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
ExtractComplexSeparated::~ExtractComplexSeparated() {
  if (this->location)                delete this->location;
  if (this->listInFilename)          delete this->listInFilename;
  if (this->locationLigandOut)       delete this->locationLigandOut;
  if (this->locationProteinOut)      delete this->locationProteinOut;
  if (this->listResiduesBindingSite) delete this->listResiduesBindingSite;
  if (this->outList)                 delete this->outList;
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
void ExtractComplexSeparated::Location(String* location) {
  if (location) {
    if (this->location) delete this->location;
    this->location = location;
  }
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
void ExtractComplexSeparated::ListInFilename(String* listInFilename) {
  if (listInFilename) {
    if (this->listInFilename) delete this->listInFilename;
    this->listInFilename = listInFilename;
  }
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
void ExtractComplexSeparated::LocationLigandOut(String* locationLigandOut) {
  if (locationLigandOut) {
    if (this->locationLigandOut) delete this->locationLigandOut;
    this->locationLigandOut = locationLigandOut;
  }
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
void ExtractComplexSeparated::LocationProteinOut(String* locationProteinOut) {
  if (locationProteinOut) {
    if (this->locationProteinOut) delete this->locationProteinOut;
    this->locationProteinOut = locationProteinOut;
  }
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
void ExtractComplexSeparated::ListResiduesBindingSite(String* listResiduesBindingSite) {
  if (listResiduesBindingSite) {
    if (this->listResiduesBindingSite) delete this->listResiduesBindingSite;
    this->listResiduesBindingSite = listResiduesBindingSite;
  }
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
void ExtractComplexSeparated::OutList(String* outList) {
  if (outList) {
    if (this->outList) delete this->outList;
    this->outList = outList;
  }
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
String* ExtractComplexSeparated::Location(void) {
  return this->location;
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
String* ExtractComplexSeparated::ListInFilename(void) {
  return this->listInFilename;
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
String* ExtractComplexSeparated::LocationLigandOut(void) {
  return this->locationLigandOut;
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
String* ExtractComplexSeparated::LocationProteinOut(void) {
  return this->locationProteinOut;
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
String* ExtractComplexSeparated::ListResiduesBindingSite(void) {
  return this->listResiduesBindingSite;
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
String* ExtractComplexSeparated::OutList(void) {
  return this->outList;
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
bool ExtractComplexSeparated::GeneratedReducedDatabase() {
    
  if (!this->location           || !this->location->Length()          ||
      !this->listInFilename     || !this->listInFilename->Length()    ||
      !this->locationLigandOut  || !this->locationLigandOut->Length() ||
      !this->locationProteinOut || !this->locationProteinOut->Length())
    return false;

  TListE <String> *listFiles = new TListE <String> ();

  fstream          listFile;

  char             buffer[LENGTHLINE + 1];

  listFile.open(this->listInFilename->Out(), fstream::in);
  while (!listFile.eof()) {
    listFile.getline(buffer, LENGTHLINE);
    String* nameFile = new String(buffer);
    nameFile->Trim();
    if (nameFile->Length()) listFiles->Add(nameFile);
  }
  listFile.close();

  cout << "Reading Files..." << endl;
  cout << "---------------------------------------------------------------------------------" << endl;

  listFiles->SetInitial();

  while (listFiles->GetNext()) {

    char* completePath;

    completePath = new char[strlen(this->locationProteinOut->Out()) + strlen(listFiles->GetCurrent()->Out()) + 1];
    sprintf(completePath, "%s%s\0", this->locationProteinOut->Out(), listFiles->GetCurrent()->Out());
    gzFile reducedPDBFile = gzopen(completePath, "wb9");
    if (completePath) delete[] completePath;

    completePath = new char[strlen(this->locationLigandOut->Out()) + strlen(listFiles->GetCurrent()->Out()) + 1];
    sprintf(completePath, "%s%s\0", this->locationLigandOut->Out(), listFiles->GetCurrent()->Out());
    gzFile ligandPDBFile = gzopen(completePath, "wb9");
    if (completePath) delete[] completePath;

    completePath = new char[strlen(this->location->Out()) + strlen(listFiles->GetCurrent()->Out()) + 1];
    sprintf(completePath, "%s%s\0", this->location->Out(), listFiles->GetCurrent()->Out());
    cout << "File: " << completePath << endl;
    gzFile pdbFile = gzopen(completePath, "rb9");
    
    bool             condAnalyze = false;

    String*          textHETATM  = new String();
    TListE <String>* lines       = new TListE <String> ();

    while (!gzeof(pdbFile)) {

      gzgets(pdbFile, buffer, LENGTHLINE);

      if (condAnalyze) {

        if (!strncmp(buffer, "ATOM", strlen("ATOM"))) {
          condAnalyze = false;
          continue;
        }

        if (!strncmp(buffer, "HETATM", strlen("HETATM"))) {

          String* tmpBuffer = new String(buffer);
          String* atomType  = tmpBuffer->SubStr(12, 16);
          String* resName   = tmpBuffer->SubStr(17, 20);

          atomType->RTrim();
          resName->RTrim();

          if (tmpBuffer) delete tmpBuffer;

          if (strcmp(atomType->Out(), resName->Out()) && strcmp("HOH", resName->Out()))
            textHETATM->Add(buffer);

          if (atomType) delete atomType;
          if (resName)  delete resName;

        }
      }

      if (!strncmp(buffer, "TER", strlen("TER")))
        condAnalyze = true;

    }

    gzclose(pdbFile);

    String* chain             = new String();
    char*   tmpHETATM         = new char[strlen(textHETATM->Out()) + 1];
    int     counterAtomLigand = 0;

    strcpy(tmpHETATM, textHETATM->Out());

    this->SplitColumn(tmpHETATM, lines, "\n");

    chain->In("");

    lines->SetInitial();
    while (lines->SetNext()) {
      String* ChainV = lines->GetCurrent()->SubStr(21, 22);
      if (!chain->Length()) chain->In(ChainV);
      if (!strcmp(chain->Out(), ChainV->Out())) {
        String* partRecord = lines->GetCurrent()->SubStr(12, lines->GetCurrent()->Length());
        gzprintf(ligandPDBFile, "ATOM  %5d%s\n\0", ++counterAtomLigand, partRecord->Out());
        if (partRecord) delete partRecord;
      }
      else {
        if (ChainV) delete ChainV;
        break;
      }
      if (ChainV) delete ChainV;
    }

    gzprintf(ligandPDBFile, "TER\n\0");
    gzclose(ligandPDBFile);

    if (textHETATM) delete textHETATM;
    if (tmpHETATM)  delete tmpHETATM;

    pdbFile     = gzopen(completePath, "rb9");
    condAnalyze = false;

    while (!gzeof(pdbFile)) {

      gzgets(pdbFile, buffer, LENGTHLINE);

      if (!strncmp(buffer, "ATOM", strlen("ATOM"))) {

        String* line   = new String(buffer);
        String* ChainV = line->SubStr(21, 22);

        if (!strcmp(chain->Out(), ChainV->Out())) {

          if (!condAnalyze) condAnalyze = true;
          String* atomName = line->SubStr(12, 16);
          atomName->RTrim();
          
          if (!strcmp(atomName->Out(), "CA") || !strcmp(atomName->Out(), "CB"))
            gzprintf(reducedPDBFile, "%s\0", line->Out());
          
          if (atomName) delete atomName;
          
        }

        if (ChainV) delete ChainV;
        if (line)   delete line;
        
      }
      
      if (!strncmp(buffer, "TER", strlen("TER")) && condAnalyze)
        break;

    }

    gzclose(pdbFile);
    
    if (completePath) delete[] completePath;
    if (lines)        delete lines;
    if (chain)      delete chain;

    gzprintf(reducedPDBFile, "TER\n\0");
    gzclose(reducedPDBFile);

  }

  if (listFiles) delete listFiles;

  return true;
  
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
bool ExtractComplexSeparated::GeneratedReducedDatabaseLargestLigand() {

  if (!this->location           || !this->location->Length()          ||
      !this->listInFilename     || !this->listInFilename->Length()    ||
      !this->locationLigandOut  || !this->locationLigandOut->Length() ||
      !this->locationProteinOut || !this->locationProteinOut->Length())
    return false;

  TListE <String> *listFiles = new TListE <String> ();

  fstream          listFile;

  char             buffer[LENGTHLINE + 1];

  listFile.open(this->listInFilename->Out(), fstream::in);
  while (!listFile.eof()) {
    listFile.getline(buffer, LENGTHLINE);
    String* nameFile = new String(buffer);
    nameFile->Trim();
    if (nameFile->Length()) listFiles->Add(nameFile);
  }
  listFile.close();

  cout << "Reading Files..." << endl;
  cout << "---------------------------------------------------------------------------------" << endl;

  listFiles->SetInitial();

  while (listFiles->GetNext()) {

    char* completePath;
    completePath = new char[strlen(this->location->Out()) + strlen(listFiles->GetCurrent()->Out()) + 1];
    sprintf(completePath, "%s%s\0", this->location->Out(), listFiles->GetCurrent()->Out());

    BoxBindingZone*   bindingZone = new BoxBindingZone();

    String* tmpLocation = new String(completePath);
    bindingZone->Location(tmpLocation);
    UniqueLigand* uniqueLigand = bindingZone->GetLargestLingand();

    String* ideLigand = new String();
    String* resNumberB = new String();

    if (uniqueLigand) {
      ideLigand->In(uniqueLigand->IDELigand->Out());
      resNumberB->In(uniqueLigand->ResidueNumber->Out());
    }

    ideLigand->RTrim();
    resNumberB->RTrim();
    
    if (bindingZone) delete bindingZone;
    if (completePath) delete[] completePath;

    completePath = new char[strlen(this->locationProteinOut->Out()) + strlen(listFiles->GetCurrent()->Out()) + 1];
    sprintf(completePath, "%s%s\0", this->locationProteinOut->Out(), listFiles->GetCurrent()->Out());
    gzFile reducedPDBFile = gzopen(completePath, "wb9");
    if (completePath) delete[] completePath;

    completePath = new char[strlen(this->locationLigandOut->Out()) + strlen(listFiles->GetCurrent()->Out()) + 1];
    sprintf(completePath, "%s%s\0", this->locationLigandOut->Out(), listFiles->GetCurrent()->Out());
    gzFile ligandPDBFile = gzopen(completePath, "wb9");
    if (completePath) delete[] completePath;

    completePath = new char[strlen(this->location->Out()) + strlen(listFiles->GetCurrent()->Out()) + 1];
    sprintf(completePath, "%s%s\0", this->location->Out(), listFiles->GetCurrent()->Out());
    cout << "File: " << completePath << endl;
    gzFile  pdbFile = gzopen(completePath, "rb9");

    bool             condAnalyze     = false;

    TListE <String>* lines           = new TListE <String> ();

    String* chain             = NULL;
    int     counterAtomLigand = 0;
    
    while (!gzeof(pdbFile)) {

      gzgets(pdbFile, buffer, LENGTHLINE);

      if (!strncmp(buffer, "HETATM", strlen("HETATM"))) {

        String* tmpBuffer = new String(buffer);
        String* resNumber = tmpBuffer->SubStr(22, 26);
        String* resName   = tmpBuffer->SubStr(17, 20);
        String* elemSymb  = tmpBuffer->SubStr(76, 78);

        resNumber->RTrim();
        resName->RTrim();
        elemSymb->RTrim();

        if (!strcmp(ideLigand->Out(),  resName->Out())    &&
            !strcmp(resNumberB->Out(), resNumber->Out())) {

          String* textHETATM = new String(buffer);
          textHETATM->Trim();

          if (!counterAtomLigand) chain = textHETATM->SubStr(21, 22);

          String* partRecord = textHETATM->SubStr(12, textHETATM->Length());
          gzprintf(ligandPDBFile, "ATOM  %5d%s\n\0", ++counterAtomLigand, partRecord->Out());
          
          if (partRecord) delete partRecord;
          if (textHETATM) delete textHETATM;
          
        }

        if (resNumber) delete resNumber;
        if (resName)   delete resName;
        if (tmpBuffer) delete tmpBuffer;
        if (elemSymb)  delete elemSymb;

      }

    }

    gzprintf(ligandPDBFile, "TER\n\0");
    gzclose(ligandPDBFile);
    gzclose(pdbFile);

    if (ideLigand)  delete ideLigand;
    if (resNumberB) delete resNumberB;

    pdbFile     = gzopen(completePath, "rb9");
    condAnalyze = false;

    while (!gzeof(pdbFile)) {

      gzgets(pdbFile, buffer, LENGTHLINE);

      if (!strncmp(buffer, "ATOM", strlen("ATOM"))) {

        String* line   = new String(buffer);
        String* ChainV = line->SubStr(21, 22);

        if (!strcmp(chain->Out(), ChainV->Out())) {

          if (!condAnalyze) condAnalyze = true;
          String* atomName = line->SubStr(12, 16);
          atomName->RTrim();

          if (!strcmp(atomName->Out(), "CA") || !strcmp(atomName->Out(), "CB"))
            gzprintf(reducedPDBFile, "%s\0", line->Out());

          if (atomName) delete atomName;

        }

        if (ChainV) delete ChainV;
        if (line)   delete line;

      }

      if (!strncmp(buffer, "TER", strlen("TER")) && condAnalyze)
        break;

    }

    gzclose(pdbFile);

    if (completePath) delete[] completePath;
    if (lines)        delete lines;
    if (chain)      delete chain;

    gzprintf(reducedPDBFile, "TER\n\0");
    gzclose(reducedPDBFile);

  }

  if (listFiles) delete listFiles;

  return true;

}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
bool ExtractComplexSeparated::GeneratedDBCoordProtein() {

  if (!this->location                || !this->location->Length()          ||
      !this->listInFilename          || !this->listInFilename->Length()    ||
      !this->outList                 || !this->outList->Length()           ||
      !this->locationProteinOut      || !this->locationProteinOut->Length())
    return false;

  TListE <String> *listFiles = new TListE <String> ();
  fstream          listFile;
  char             buffer[LENGTHLINE + 1];

  listFile.open(this->listInFilename->Out(), fstream::in);
  while (!listFile.eof()) {
    listFile.getline(buffer, LENGTHLINE);
    String* nameFile = new String(buffer);
    nameFile->Trim();
    if (nameFile->Length()) listFiles->Add(nameFile);
  }
  listFile.close();

  cout << "Reading Files..." << endl;
  cout << "---------------------------------------------------------------------------------" << endl;

  fstream outListFile;
  outListFile.open(this->outList->Out(), fstream::out);

  listFiles->SetInitial();

  while (listFiles->GetNext()) {

    char* completePath;
    completePath = new char[strlen(this->location->Out()) + strlen(listFiles->GetCurrent()->Out()) + 1];
    sprintf(completePath, "%s%s\0", this->location->Out(), listFiles->GetCurrent()->Out());

    BoxBindingZone*   bindingZone = new BoxBindingZone();

    String* tmpLocation = new String(completePath);
    bindingZone->Location(tmpLocation);
    UniqueLigand* uniqueLigand = bindingZone->GetLargestLingand();

    String* ideLigand = new String();
    String* resNumberB = new String();

    if (uniqueLigand) {
      ideLigand->In(uniqueLigand->IDELigand->Out());
      resNumberB->In(uniqueLigand->ResidueNumber->Out());
    }

    ideLigand->RTrim();
    resNumberB->RTrim();
    
    if (bindingZone)  delete   bindingZone;
    if (completePath) delete[] completePath;

    completePath = new char[strlen(this->locationProteinOut->Out()) + strlen(listFiles->GetCurrent()->Out()) + 1];
    sprintf(completePath, "%s%s\0", this->locationProteinOut->Out(), listFiles->GetCurrent()->Out());
    gzFile reducedPDBFile = gzopen(completePath, "wb9");
    if (completePath) delete[] completePath;

    completePath = new char[strlen(this->location->Out()) + strlen(listFiles->GetCurrent()->Out()) + 1];
    sprintf(completePath, "%s%s\0", this->location->Out(), listFiles->GetCurrent()->Out());
    cout << "File: " << completePath << endl;
    gzFile  pdbFile = gzopen(completePath, "rb9");

    bool             condAnalyze       = false;

    TListE <String>* lines             = new TListE <String> ();
    String*          chain             = NULL;
    
    while (!gzeof(pdbFile)) {

      gzgets(pdbFile, buffer, LENGTHLINE);
      
      if (!strncmp(buffer, "HETATM", strlen("HETATM"))) {

        String* tmpBuffer = new String(buffer);
        String* resNumber = tmpBuffer->SubStr(22, 26);
        String* resName   = tmpBuffer->SubStr(17, 20);

        resNumber->RTrim();
        resName->RTrim();
        
        if (!strcmp(ideLigand->Out(),  resName->Out())    &&
            !strcmp(resNumberB->Out(), resNumber->Out())) {

          String* textHETATM = new String(buffer);
          textHETATM->Trim();

          chain = textHETATM->SubStr(21, 22);
          
          if (textHETATM) delete textHETATM;
          if (resNumber)  delete resNumber;
          if (resName)    delete resName;
          if (tmpBuffer)  delete tmpBuffer;
          
          break;
          
        }

      }

    }

    gzclose(pdbFile);

    if (ideLigand)  delete ideLigand;
    if (resNumberB) delete resNumberB;
    
    outListFile << this->ExtractPDBCodeFromNamefile(listFiles->GetCurrent())->Out() << "," << chain->Out() << endl;
    
    condAnalyze       = false;
    pdbFile = gzopen(completePath, "rb9");
    
    while (!gzeof(pdbFile)) {

      gzgets(pdbFile, buffer, LENGTHLINE);

      if (!strncmp(buffer, "ATOM", strlen("ATOM"))) {

        String* line   = new String(buffer);
        String* ChainV = line->SubStr(21, 22);

        if (!strcmp(chain->Out(), ChainV->Out())) {
          if (!condAnalyze) condAnalyze = true;
          gzprintf(reducedPDBFile, "%s\0", line->Out());
        }

        if (ChainV) delete ChainV;
        if (line)   delete line;

      }

      if (!strncmp(buffer, "TER", strlen("TER")) && condAnalyze)
        break;

    }

    gzclose(pdbFile);

    if (completePath) delete[] completePath;
    if (lines)        delete lines;
    if (chain)        delete chain;

    gzprintf(reducedPDBFile, "TER\n\0");
    gzclose(reducedPDBFile);

  }

  outListFile.close();
    
  if (listFiles) delete listFiles;

  return true;

}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
bool ExtractComplexSeparated::SplitColumn(char* buffer, TListE<String>* columns, char* characters) {

  if (!buffer || !columns || !characters) return false;

  char *part = strtok(buffer, characters);

  while (part) {
    String* cell = new String(part);
    cell->Trim();
    columns->Add(cell);
    part = strtok(NULL, characters);
  }

  return true;

}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
bool ExtractComplexSeparated::SplitColumn(char* buffer, TListE<String>* columns, const char* characters) {

  if (!buffer || !columns || !characters) return false;

  char *part = strtok(buffer, characters);

  while (part) {
    String* cell = new String(part);
    cell->Trim();
    columns->Add(cell);
    part = strtok(NULL, characters);
  }

  return true;

}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
char ExtractComplexSeparated::OneLetterAACode(String* code) {

  if      (!code)                return ' ';
  if      (code->Contain("ALA")) return 'A';
  else if (code->Contain("ARG")) return 'R';
  else if (code->Contain("ASN")) return 'N';
  else if (code->Contain("ASP")) return 'D';
  else if (code->Contain("ASX")) return 'B';
  else if (code->Contain("CYS")) return 'C';
  else if (code->Contain("GLU")) return 'E';
  else if (code->Contain("GLN")) return 'Q';
  else if (code->Contain("GLX")) return 'Z';
  else if (code->Contain("GLY")) return 'G';
  else if (code->Contain("HIS")) return 'H';
  else if (code->Contain("ILE")) return 'I';
  else if (code->Contain("LEU")) return 'L';
  else if (code->Contain("LYS")) return 'K';
  else if (code->Contain("MET")) return 'M';
  else if (code->Contain("PHE")) return 'F';
  else if (code->Contain("PRO")) return 'P';
  else if (code->Contain("SER")) return 'S';
  else if (code->Contain("THR")) return 'T';
  else if (code->Contain("TRP")) return 'W';
  else if (code->Contain("TYR")) return 'Y';
  else if (code->Contain("VAL")) return 'V';
  else                           return ' ';

}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
String* ExtractComplexSeparated::ExtractPDBCodeFromNamefile(String* nameFile) {
  if (!nameFile) return NULL;
  String* pdbId = new String();
  for (int i = 3; i < 7; i++)
    pdbId->Add(nameFile->Out(i));
  return pdbId;
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//

